﻿using MediatR;
using SmartCity.ProcessEngine.API.Domain;
using SmartCity.ProcessEngine.API.ErrorCode;
using SmartCity.ProcessEngine.API.Infrastructrue.Extensions;
using SmartCity.ProcessEngine.API.Infrastructrue.Interfaces;
using SmartCity.ProcessEngine.API.Read.Applications.Commands;
using SmartCity.ProcessEngine.API.Read.DTOS;
using System.Collections.Generic;

namespace SmartCity.ProcessEngine.API.Read.Applications.CommandHandlers
{

    public class IndustyQueryCommandHandler : IRequestHandler<IndustyQueryCommand, APIResult<List<IndustyDTO>>>
    {
        private readonly IBaseRespository<Industry> industryRep;

        public IndustyQueryCommandHandler(IBaseRespository<Industry> industryRep)
        {
            this.industryRep = industryRep;
        }

        public Task<APIResult<List<IndustyDTO>>> Handle(IndustyQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<IndustyDTO>> result=new APIResult<List<IndustyDTO>>();
            result.Code=APIResultCode.SearchSuccess;
            result.Message=APIResultCode.SearchSuccess.GetDescription();

            var res = from a in industryRep.GetAll()
                      select new IndustyDTO()
                      {
                          IndustryId=a.IndustryId,
                          IndustyName=a.IndustyName,
                      };
            result.Data=res.ToList();
            return Task.FromResult(result);
        }
    }
}
